<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/displaytag.tld" prefix="display"%>
<%@ page import="java.util.*"%>

<html>
<script type="text/javascript"
	src="<%= request.getContextPath() + "/js/popUP.js" %>"></script>
<link href="<%= request.getContextPath() + "/css/bloques.css" %>"
	rel="stylesheet" type="text/css">
<link href="<%= request.getContextPath() + "/css/table.css" %>"
	rel="stylesheet" type="text/css">
<script src="<%=request.getContextPath()%>/js/dateValidation.js"
	type="text/javascript"></script>
<script type="text/javascript"
	src="<%=request.getContextPath() + "/js/jquery-1.8.0.js"%>"></script>
<script type="text/javascript"
	src="<%=request.getContextPath()
					+ "/js/jquery-ui-1.10.3.custom.min.js"%>"></script>
<script type="text/javascript"
	src="<%=request.getContextPath()
					+ "/js/jquery.ui.datepicker-es.js"%>"></script>
<link rel="stylesheet"
	href="<%=request.getContextPath()
					+ "/css/ui-lightness/jquery-ui-1.10.3.custom.css"%>" />

<script type="text/javascript">
$(document).ready(function() {
	
	$("#buscarBtn").click(function(){		
		if($("#sede").val() != 'nulo' || $("#programa").val() != 'nulo'){
			$('#fechaInicial').val($('#fechaIni').val());
			$('#fechaFinal').val($('#fechaFin').val());
			var action = '<%=request.getContextPath()
				+ "/Reportes/Detallados/ReportDetBeneficiario.do"%>';
			
			$("#acciones").val('BuscarTodo');
			$("#mainForm").attr("action", action);
			$("#mainForm").attr("target", "_self");
			
			if( ($("#fechaInicial").val() == '' && $("#fechaFinal").val() == '')){
				$("#mainForm").submit();
			}else{
				var fIniValida = isDate($("#fechaInicial").val());
				var fFinValida = isDate($("#fechaFinal").val());
				if(!fIniValida){
					alert('Fecha inicial no valida.');
					return false;
				}else if(!fFinValida){
					alert('Fecha final no valida.');
					return false;
				}else{
					if( $.datepicker.parseDate("dd/mm/yy", $("#fechaInicial").val()) > $.datepicker.parseDate("dd/mm/yy", $("#fechaFinal").val())){
						alert('Fecha inicial no puede ser mayor que la fecha final.');
						return false;
					}
				}
				$("#mainForm").submit();
			}			
			
		}else{
			alert(' seleccione un programa o una sede');
			return false;
		}
	});
	
	//boton generar
	$("#generarBtn").click(function(){
		var i;
		for (i = 0; i < document.mainForm.generar.length; i++) {
			if (document.mainForm.generar[i].checked == true) {
				$("#posicion").val(i);
				break;
			}
		}
		$("#mainForm").attr("target", "_self");
		$("#mainForm").submit();
	});
	
	//cuando cambia el valor seleccionado de la lista de areas.
	$("#area").change(function(){		
		$('#fechaInicial').val($('#fechaIni').val());
		$('#fechaFinal').val($('#fechaFin').val());
		var action = '<%=request.getContextPath()
			+ "/Reportes/Detallados/ReportDetBeneficiario.do"%>';
		var target = '_self';
		$("#mainForm").attr("action", action);
		$("#mainForm").attr("target", target);
		$("#acciones").val('areas');
		$("#mainForm").submit();
	});
	
	//cuando cambia el valor seleccionado de la lista de programas.
	$("#programa").change(function(){				
		$('#fechaInicial').val($('#fechaIni').val());
		$('#fechaFinal').val($('#fechaFin').val());
		var action = '<%=request.getContextPath()
			+ "/Reportes/Detallados/ReportDetBeneficiario.do"%>';
		$("#mainForm").attr("action", action);
		$("#mainForm").attr("target", "_self");
		$('#acciones').val('BuscarSubprogrmas');		
		$('#mainForm').submit();
	});
	
});
</script>

<!-- DatePickers -->
<script type="text/javascript">
$.datepicker.setDefaults({
	  showOn: "button",
	  buttonImageOnly: true,
	  buttonImage: "<%=request.getContextPath() + "/images/Calendar.png"%>",
	  buttonText : "Calendario"
	});
	$(function() {
		$("#fechaIni").datepicker({
			changeMonth : true,
			changeYear : true
		});
	});
	$(function() {
		$("#fechaFin").datepicker({
			changeMonth : true,
			changeYear : true
		});
	});
</script>

<script src="<%=request.getContextPath()%>/js/displaytag.js"
	type="text/javascript"></script>
<form name="mainForm" id="mainForm"
	action="<%=request.getContextPath()+"/Reportes/Detallados/SelectionFilter.do"%>"
	method="GET">
	<input type="HIDDEN" name="seleccionar" value="ir">
	<input type="HIDDEN" name="codigo" value="nulo"> 
	<input type="hidden" name="acciones" id="acciones"> 
	<input type="hidden" name="fechaInicial" id="fechaInicial" value="" /> 
	<input type="hidden" name="fechaFinal" id="fechaFinal" value="" />
	<div align="center">
		<table class="tablaGenericaWidth70">
			<tr>
				<td class="titulosenblanco" colspan="3">
					<DIV align="center">
						<STRONG>Reporte&nbsp;Detallado&nbsp;Beneficiario </STRONG>
					</DIV>
				</td>
			</tr>
			<tr>
				<td class="titulosenblanco" colspan="3">&nbsp;</td>
			</tr>
			<tr>
				<td align="center" class="celdatabla" colspan="3">Seleccione
					los criterios de busqueda</td>
			</tr>
			<tr>
				<td class="titulosenblanco" colspan="3">&nbsp;</td>
			</tr>
			<tr>
				<td class="celdatabla" width="31%">Sede:</td>
				<td width="44%"><logic:notPresent name="sedes">
						<DIV align="center">
							<%= session.getAttribute("msg")%>
							<%session.removeAttribute("msg");%>
						</DIV>
					</logic:notPresent> <%   Object codeSede = request.getParameter("code"); 
            if(codeSede==null) codeSede = "nulo";
       %>
					<div align="left">
						<logic:present name="sedes">
							<logic:iterate id="sede" name="sedes" length="1"
								type="co.gov.medellin.ssti.sub.model.vo.SedeVO">
								<html:select name="sede" styleId="sede" property="code" title="Sede"
									styleClass="formInputOutput" value="<%=(String)codeSede%>">
									<option value="nulo" selected="selected">Seleccione
										una sede</option>
									<html:options name="sede" labelName="codeSede"
										labelProperty="nombre" property="code" collection="sedes" />
								</html:select>
							</logic:iterate>
						</logic:present>
					</div></td>
				<td class="celdatabla" width="25%">&nbsp;</td>
			<tr>
				<td class="celdatabla" width="31%">Secretarias:</td>
				<td width="44%"><logic:notPresent name="areas">
						<DIV align="center">
							<%= session.getAttribute("msg")%>
							<%session.removeAttribute("msg");%>
						</DIV>
					</logic:notPresent> <%   Object codeArea = request.getParameter("codearea"); 
            if(codeArea==null) codeArea = "nulo";     
       %>
					<div align="left">
						<logic:present name="areas">
							<logic:iterate id="area" name="areas" length="1"
								type="co.gov.medellin.ssti.sub.model.vo.AreaVO">
								<html:select name="area" styleId="area" property="codearea" title="Area"
									styleClass="formInputOutput" value="<%=(String)codeArea%>" >
									<option value="nulo" selected="selected">Seleccione
										una secretaria</option>
									<html:options name="area" labelName="codeArea"
										labelProperty="nombre" property="codearea" collection="areas" />
								</html:select>
							</logic:iterate>
						</logic:present>
					</div></td>
				<td class="celdatabla" width="25%">&nbsp;</td>
			</tr>

			<tr>
				<td class="celdatabla" width="31%">Programa:</td>
				<td width="44%"><logic:notPresent name="programas">
						<DIV align="center">
							<%= session.getAttribute("msg")%>
							<%session.removeAttribute("msg");%>
						</DIV>
					</logic:notPresent> <%   Object codePrograma = request.getParameter("codePrograma"); %>
					<div align="left">
						<logic:present name="programas">
							<logic:iterate id="programa" name="programas" length="1"
								type="co.gov.medellin.ssti.sub.model.vo.ProgramaVO">
								<html:select name="programa" styleId="programa" property="codePrograma"
									title="Programa" styleClass="formInputOutput"
									value="<%=(String)codePrograma%>">
									<option value="nulo">Seleccione un programa</option>
									<html:options name="programas" labelName="codigo"
										labelProperty="nombre" property="code" collection="programas" />
								</html:select>
							</logic:iterate>
						</logic:present>
					</div></td>
				<td class="celdatabla" width="25%">&nbsp;</td>
			</tr>
			<% 
        String strCodePrograma = (String)codePrograma;
            if(codePrograma != null && !strCodePrograma.equals("nulo")){
        %>
			<tr>
				<td class="celdatabla" width="31%">Beneficio:</td>
				<td width="44%">
					<div align="left">
						<logic:notPresent name="subprogramas">
							<DIV align="center">
								<%= session.getAttribute("msg")%>
								<%session.removeAttribute("msg");%>
							</DIV>
						</logic:notPresent>
						<%   Object codeSubPrograma = request.getParameter("codeSubPrograma"); 
             if(codeSubPrograma==null) codeSubPrograma = "nulo";
       %>
						<logic:present name="subprogramas">
							<logic:iterate id="subprograma" name="subprogramas" length="1"
								type="co.gov.medellin.ssti.sub.model.vo.SubprogramaVO">
								<html:select name="subprograma" styleId="subprograma" property="codeSubPrograma"
									title="Programa" styleClass="formInputOutput"
									value="<%=(String)codeSubPrograma%>">
									<option value="nulo">Seleccione un subprograma</option>
									<html:options name="subprogramas" labelName="codigo"
										labelProperty="nombre" property="code"
										collection="subprogramas" />
								</html:select>
							</logic:iterate>
						</logic:present>
					</div>
				</td>
				<td class="celdatabla" width="25%">&nbsp;</td>
			</tr>
			<% 
      }  
  %>

			<tr>
				<td class="celdatabla" width="31%">
					<p>
						Fecha inicial:
					</p>
				</td>
				<% String fechaInicial = (request.getParameter("fechaInicial") == null) ? "" : request.getParameter("fechaInicial"); %>
				<td align="left" class="celdatabla">
					<input id="fechaIni" class="formInputOutput" value="<%= fechaInicial %>" />
				</td>

				<td class="celdatabla" width="25%">&nbsp;</td>
			</tr>
			
			<tr>
				<td class="celdatabla" width="31%">
					<p>
						Fecha final:
					</p>
				</td>
				<% String fechaFinal = (request.getParameter("fechaFinal") == null) ? "" : request.getParameter("fechaFinal"); %>
				<td align="left" class="celdatabla">
					<input id="fechaFin" class="formInputOutput" value="<%= fechaFinal %>"/>
				</td>

				<td class="celdatabla" width="25%">&nbsp;</td>
			</tr>
			
			<tr>
				<td class="celdatabla" width="31%">&nbsp;</td>
				<td width="44%">
					<div align="center">
						<input type="hidden" name="accion" id="accion" value="" />
						<input type="button" value="Generar" name="buscarBtn" id="buscarBtn" />
						<P>&nbsp;</P>
					</div>
				</td>
				<td class="celdatabla" width="25%">&nbsp;</td>
			</tr>
			<tr>
				<td colspan="3" align="center"><logic:present name="msg">
						<DIV align="center"><%=session.getAttribute("msg")%></DIV>
						<%session.removeAttribute("msg");%>
					</logic:present></td>
			</tr>
		</table>
	</div>
	<input type="HIDDEN" name="posicion" />
</form>
</html>